<?php
require_once("../../controllers/init.php");
//echo "Filesystem root = ".$FILE_SYSTEM_ROOT."\n<br>";
require_once($FILE_SYSTEM_ROOT."/controllers/authentication.php");
//echo "logged on - ".(($IS_LOGGED_ON)?"true\n":"false\n");

require_once($FILE_SYSTEM_ROOT."/../MSWebGUI/Mail/Message.php");


// get all users

$users = $GLOBALS['USEREMAILS'];
$currentUser = $users[$GLOBALS['USER_ID']];


$message = new Message();
$message->setSubject("SNAP message from ".$currentUser['LongName']);
$message->setFrom($currentUser['email']);


if (isset($_POST['Recipients']))
{
	$recipients = ($_POST['Recipients']);
	if (isset($_POST['Message']))
	{
		$messageBody = ($_POST['Message']);
		$message->setMessageBody($messageBody);
		foreach ($recipients as $recipient)
		{
			$message->addRecipient($users[$recipient]['email']);
		}

		$message->send();
		echo "Message sent";
	
	}
}
else echo "Message not sent";


